#include "pthread.hpp"
#include "thread_pool.hpp"
#include <memory>

using namespace std;
using namespace ThreadModule;

int main()
{
    EnableFile();
    //LOG(1,g_issave,"hhhhh");
    //智能指针 c++11构建  new一个thread_pool类型的对象来构造
    //unique_ptr<thread_pool<int>> pool(new thread_pool<int>(10));
    //智能指针 c++14构建 make_unique返回一个thread_pool类型的对象
    unique_ptr<thread_pool<Task>> pool = make_unique<thread_pool<Task>>(4);

    pool->Init();

    pool->Start();

    srand(time(nullptr)^ getpid());
    int tasknum = 10;
    while(tasknum--)
    {
        int a = rand() %10 + 1;
        int b = rand() %5 + 1;
        usleep(1000);
        Task t(a,b);
        LOG(INFO, "main thread push task: %s", t.Add().c_str());  
        pool->Enqueue(t);
    }

    sleep(3);

    pool->Stop();

    pool->Wait();





    //string Logstring(string name,int line,int level,const char* format,...)
    // string message = LOG(0, "%s", "hello");
    // string ret = LOG(1, "hello world");

    // cout << message << endl;
    // cout << ret << endl;
    // return 0;
}